package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 家属和老人关联Controller
 * 
 * @author zyh
 * @date 2025-10-23
 */
@RestController
@RequestMapping("/nursing/familyElder")
@Api(tags = "家属和老人关联的接口")
public class FamilyMemberElderController extends BaseController
{
    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    /**
     * 查询家属和老人关联列表
     */
    @ApiOperation("查询家属和老人关联列表")
    @PreAuthorize("@ss.hasPermi('nursing:familyElder:list')")
    @GetMapping("/list")
    public TableDataInfo list(FamilyMemberElder familyMemberElder)
    {
        startPage();
        List<FamilyMemberElder> list = familyMemberElderService.selectFamilyMemberElderList(familyMemberElder);
        return getDataTable(list);
    }

    /**
     * 导出家属和老人关联列表
     */
    @ApiOperation("导出家属和老人关联列表")
    @PreAuthorize("@ss.hasPermi('nursing:familyElder:export')")
    @Log(title = "家属和老人关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FamilyMemberElder familyMemberElder)
    {
        List<FamilyMemberElder> list = familyMemberElderService.selectFamilyMemberElderList(familyMemberElder);
        ExcelUtil<FamilyMemberElder> util = new ExcelUtil<FamilyMemberElder>(FamilyMemberElder.class);
        util.exportExcel(response, list, "家属和老人关联数据");
    }

    /**
     * 获取家属和老人关联详细信息
     */
    @ApiOperation("获取家属和老人关联详细信息")
    @PreAuthorize("@ss.hasPermi('nursing:familyElder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "家属和老人关联ID", required = true)
            @PathVariable("id") Long id)
    {
        return success(familyMemberElderService.selectFamilyMemberElderById(id));
    }

    /**
     * 新增家属和老人关联
     */
    @ApiOperation("新增家属和老人关联")
    @PreAuthorize("@ss.hasPermi('nursing:familyElder:add')")
    @Log(title = "家属和老人关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(value = "家属和老人关联实体")
            @RequestBody FamilyMemberElder familyMemberElder)
    {
        return toAjax(familyMemberElderService.insertFamilyMemberElder(familyMemberElder));
    }

    /**
     * 修改家属和老人关联
     */
    @ApiOperation("修改家属和老人关联")
    @PreAuthorize("@ss.hasPermi('nursing:familyElder:edit')")
    @Log(title = "家属和老人关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(value = "家属和老人关联实体")
            @RequestBody FamilyMemberElder familyMemberElder)
    {
        return toAjax(familyMemberElderService.updateFamilyMemberElder(familyMemberElder));
    }

    /**
     * 删除家属和老人关联
     */
    @ApiOperation("删除家属和老人关联")
    @PreAuthorize("@ss.hasPermi('nursing:familyElder:remove')")
    @Log(title = "家属和老人关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(familyMemberElderService.deleteFamilyMemberElderByIds(ids));
    }
}
